<template>
	<view>
		
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			const _this = this;
			var conversationList = [];
			_this.$im.watch({
				conversation: function(event){
					var updatedConversationList = event.updatedConversationList;
						console.log('更新会话汇总:', updatedConversationList);
						console.log('最新会话列表:', _this.$im.Conversation.merge({
						conversationList,
						updatedConversationList
					}));
				},
				message: function(event){
					var message = event.message;
					console.log('收到新消息:', message);
				},
				status: function(event){
					var status = event.status;
					console.log('连接状态码:', status);
				},
				expansion: function(event) {
					var updatedExpansion = event.updatedExpansion;
					var deletedExpansion = event.deletedExpansion;
					console.log('消息扩展已更新', updatedExpansion);
					console.log('消息扩展被删除', deletedExpansion);
				},
				chatroom: function(event) {
					var updatedEntries = event.updatedEntries;
					console.log('聊天室 KV 存储监听更新:', updatedEntries);
				}
			})
			_this.$api.findByHealthId().then((res)=>{
				if(res.data.StatusCode == 200){
					const data = res.data.Result
					_this.$api.IMgetUserToken({id:data.id,name:data.realName,portrait:data.headPicture || 'http://jlm-file.oss-cn-hangzhou.aliyuncs.com/jlm-product/image/portrait/2020/11/9472ab92fe90400fbee424c2d6b02fb0.png'}).then((responest)=>{
						const token = responest.data.token
						_this.$im.connect({token:token}).then(function(user) {
							_this.userId  = user.id
							_this.status = '链接成功'
							// _this.$im.Conversation.getTotalUnreadCount().then(function(totalUnreadCount) {
							//   console.log('获取未读总数成功', totalUnreadCount);
							// });
							_this.$im.Conversation.getList({count: 30}).then(function(conversationList) {
							  console.log('获取会话列表成功', conversationList);
							});
							console.log('链接成功, 链接用户 id 为: ', user.id);
						}).catch(function(error) {
							_this.status = '链接失败'
							_this.hisMessage = []
							console.log('链接失败: ', error.code, error.msg);
						});
					})
				}  
			})
		},
		methods: {
			
		}
	}
</script>

<style>

</style>
